$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/userslog2/list',
        datatype: "json",
        colModel: [			
			// { label: 'ID', name: 'orderId', index: 'order_id',align: "center", width: 100, key: true,
			// 	formatter:function(value,options,rowData){
			// 		return "<a onclick=vm.openInfo('"+value+"')>"+value+"</a>";
			// 	}
			// },
            { label: '用户ID', name: 'userId', index: 'userId',align: "center", width:80 },
			{ label: '名称', name: 'nickName', index: 'nickName',align: "center", width: 80 },
			{ label: '头像', name: 'avatarUrl', index: 'avatarUrl',align: "center", width: 50, formatter: function(value,options,rowData) {
					return '<img src="'+value+'" width="60px" height="60px" />';
				}
			},
			{ label: '公众号标识', name: 'gzhCode', index: 'gzhCode',align: "center", width: 50 },
            { label: '创建时间', name: 'createTime', index: 'createTime',align: "center", width: 80},
        ],
		viewrecords: true,
        height: "100%",
        rowNum: 18,
		rowList : [18,30,50],
        rownumbers: true, 
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
		postData:{"startDate":vm.q.startDate,"endDate":vm.q.endDate,"gzhCode":vm.q.gzhCode},
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });


	$.ajax({
		type: "POST",
		async:false,
		url: baseURL + 'sys/buserinfo/getUserGzhList',
		contentType: "application/json",
		success: function(r){
			if(r.code==0){
				//vm.bbrandinfo=r.brandInfo;
				$("#selectUserGzhList").append(
					"<option value=''>全部平台</option>");
				for(var i=0;i<r.userGzhList.length;i++){
					$("#selectUserGzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
				}
			}
		}
	});



});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		wantedUsersLog: {},
		q:{
			startDate:null,
			endDate:null,
			gzhCode:''
		}
	},
	// 页面加载完毕后触发的事件
	mounted() {
		var vm = this;
		vm.q.startDate = vm.todayDate(); // 默认显示为当天时间
		vm.q.endDate = vm.todayDate();
	},
	methods: {
		todayDate: function() {
			let now = new Date();

			let y = now.getFullYear(); //年
			let m = now.getMonth() + 1 + ''; //月
			let d = now.getDate() + ''; //日

			m = m.length == 1 ? '0' + m : m;
			d = d.length == 1 ? '0' + d : d;
			return y + '-' + m + '-' + d;
		},
		query: function () {
			vm.reload();

			$.ajax({
				type: "POST",
				async:false,
				url: baseURL + 'sys/bordervital/vitalSum',
				contentType: "application/json",
				data: JSON.stringify({'startDate':vm.q.startDate,'endDate':vm.q.endDate,'gzhCode':vm.q.gzhCode}),
				success: function(r){
					if(r.code==0 && r.vitalSum!=null){
						$("#t1Count").html(r.vitalSum.t1Count);
						$("#totalAmount").html(r.vitalSum.totalAmount);
						$("#t0Count").html(r.vitalSum.t0Count);
						$("#totalAmountT1").html(r.vitalSum.totalAmountT1);
						$("#t2Count").html(r.vitalSum.t2Count);
						$("#totalAmountT2").html(r.vitalSum.totalAmountT2);
					}
				}
			});

		},
		openInfo: function (e) {
			var orderId =e;
			if(orderId == null){
				return ;
			}
			vm.showList = false;
			vm.title = "修改";

			vm.getInfo(orderId)
		},
		// getInfo: function(orderId){
		// 	$.get(baseURL + "sys/borderinfo/info/"+orderId, function(r){
        //         vm.bOrderInfo = r.bOrderInfo;
		// 		// if(vm.bOrderInfo.itemId==1){
		// 		// 	vm.bOrderInfo.itemId="半年会员";
		// 		// }else if(vm.bOrderInfo.itemId==2){
		// 		// 	vm.bOrderInfo.itemId= "一年会员";
		// 		// }else if(vm.bOrderInfo.itemId==3){
		// 		// 	vm.bOrderInfo.itemId= "三年会员";
		// 		// }
        //         $("#drawback").hide();
		// 		if(vm.bOrderInfo.transStatus==0){
		// 			vm.bOrderInfo.transStatusText="待支付";
		// 		}else if(vm.bOrderInfo.transStatus==1){
        //             vm.bOrderInfo.transStatusText="已支付";
        //             $("#drawback").show();
        //         }else if(vm.bOrderInfo.transStatus==2){
        //             vm.bOrderInfo.transStatusText="已退款";
        //         }
		//
        //     });
		// },
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
				postData:{"startDate":vm.q.startDate,"endDate":vm.q.endDate,"gzhCode":vm.q.gzhCode}
            }).trigger("reloadGrid");
		}
	}
});